package instrarbre;

import exprarbre.ASAExpr;
import java.util.HashMap;

public class ASAFor extends ASAInstr {

    private ASAExpr expression1;
    private ASAExpr expression2;
    private ASAExpr expression3;
    private ASAInstr instruction;

    public ASAFor(ASAExpr expression1, ASAExpr expression2, ASAExpr expression3, ASAInstr instruction) {
        this.expression1 = expression1;
        this.expression2 = expression2;
        this.expression3 = expression3;
        this.instruction = instruction;
    }

    @Override
    public ASAInstr getInstr() {
        return instruction;
    }

    @Override
    public void interpreter(HashMap<String, Integer> affectation) {
        expression1.evalue(affectation);
        while (expression2.evalue(affectation) != 0) {
            expression3.evalue(affectation);
            try {
                instruction.interpreter(affectation);
            }
            catch (BreakException e) {
                break;
            }
            catch (ContinueException e) {
                continue;
            }
        }
    }
}